require('../../assets/css/index.js')
require('../../assets/fonts/font/iconfont.css')
require('../../assets/lib/swiper/swiper-bundle.css')
let Swiper = require('../../assets/lib/swiper/swiper-bundle.js')
require('../../utils/local.js')
let https = require('../../utils/https.js')

// 引入公共js
let dom = require('../../utils/dom.js')
const local = require('../../utils/local.js')
//引入当前页面的less文件
require('./sportsData.less')
// 当前页面js
dom.isLogin()
import * as echarts from 'echarts';



dom.ready(function () {
  // 1接口数据获取
  function getsporteData() {
    https.get('/api/exercise', {}, function (res) {
      if (res.errno == 0) {
        let xData = res.data.days.map(v => {
          return v.date.slice(5);
        })
        // console.log(xData);//x轴

        let yData = res.data.days.map(v => {
          // console.log(v);
          return v.sumDuration;
        })
        // console.log(yData);//y轴

        dom.getEle("#seconds").innerHTML = res.data.sum7Duration;
        dom.getEle("#calorie").innerHTML = res.data.sum7Calorie;
        // 上传头像
        let userData=local.get('userInfo');
        dom.getEle("#pic").src=https.hostUrl+userData.imgUrl

        console.log(https.hostUrl+userData.imgUrl);
        showEchart("#sportTime", xData, yData)

      }
    })
  }
  getsporteData();
  function showEchart(obj, xData, yData) {
    var myChart = echarts.init(dom.getEle(obj));
    var option = {
      // 标题组件
      title: {
        text: '7天运动时长'
      },

      xAxis: {
        // x轴
        type: 'category',
        data: xData,
        axisLabel: {
          show: true,
          rotate: 45,
        }
      },
      yAxis: {
        // y轴
        type: 'value'
      },
      // 数据项
      series: [
        {
          data: yData,
          type: 'bar',
          showBackground: true,
          backgroundStyle: {
            color: 'rgba(180, 180, 180, 0.2)'
          }
        }
      ]
    };
    myChart.setOption(option);
  };
  var myChart = echarts.init(dom.getEle("#sportPie"));
  var option = {
    title: {
      text: '运动分类'
    },

    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },
    series: [
      {
        name: 'Access From',
        type: 'pie',
        radius: ['40%', '70%'],
        avoidLabelOverlap: false,
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: false,
          position: 'center'
        },
        emphasis: {
          label: {
            show: true,
            fontSize: '40',
            fontWeight: 'bold'
          }
        },
        labelLine: {
          show: false
        },
        data: [

          { value: 25, name: '跑步' },
          { value: 35, name: '骑行' },
          { value: 40, name: '训练' }
        ]
      }
    ]
  };
  myChart.setOption(option);
  // 返回
  dom.getEle(".return").addEventListener("click", function () {
    window.history.go(-1);
  })


})